package com.nancy.ioc.BeanFactoryPostProcessor.conditional;

import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.ConfigurationCondition;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Random;

/**
 * @author zhouguangfeng
 * @date 2020/6/2 18:55
 */
public class BeanConfigurationCondition implements ConfigurationCondition {

    @Override
    public ConfigurationPhase getConfigurationPhase() {
        return ConfigurationPhase.PARSE_CONFIGURATION;
    }

    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        // 随机匹配是否加载
        boolean g = new Random().nextBoolean() ;
        System.out.println("BeanConfigurationCondition :" + g);
        return  g;
    }

}
